package com.smugmugsoftware.airconcalc.advanced;


import java.util.Vector;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

public class AdvancedNewRoomFragment extends Fragment implements NewRoomFragmentInterface {

	protected static final int WALL = 9001;
	protected static final int WINDOW_DOOR = 9002;
	protected static final int CEILING_FLOOR = 9003;
	protected static final int SENSIBLE_LOAD = 9004;

	private SharedPreferences prefs;
	private MainActivityInterface activity;

	private boolean somethingChanged;
	private View thisView;
	private Room thisRoom;
	private ListView celFloorList;
	private ListView wallList;
	private boolean[] isCathedral;
	private int windowType;
	private ListView sensibleList;
	private ListView winDoorList;
	private Spinner nameSpinner;

	public AdvancedNewRoomFragment() {}

	public AdvancedNewRoomFragment(Room room) {
		this.thisRoom = room;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		prefs = getActivity().getSharedPreferences("config.dat", Context.MODE_PRIVATE);
		
		setRetainInstance(true);

		isCathedral = new boolean[] { false, false };
		windowType = 0;

		if (savedInstanceState != null && savedInstanceState.getParcelable("NEW_ROOM_FRAGMENT_ROOM") != null) {
			thisRoom = savedInstanceState.getParcelable("NEW_ROOM_FRAGMENT_ROOM");
		}
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try {
			this.activity = (MainActivityInterface) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString() + " must implement OnHeadlineSelectedListener");
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		thisView = inflater.inflate(R.layout.advanced_new_room_fragment, container, false);
		thisView.findViewById(R.id.name_custom_wrapper).setVisibility(View.GONE);
		
		activity.displayInfoDialog(thisView.getContext(), InformationDialog.NEW_ROOM_FIRST_RUN, "NEW_ROOM_FIRST_RUN");

		String[] defaultNameList = getResources().getStringArray(R.array.name_array);
		final ArrayAdapter<String> nameSpinnerAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item);   
		nameSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		nameSpinnerAdapter.add("< CUSTOM >");
		String additionalNames = prefs.getString("USER_ROOM_NAMES", "");
		if (additionalNames.length() > 0) {
			String[] additionalNamesArray = additionalNames.split(",");
			for (int i = 0; i < additionalNamesArray.length; i++) {
				nameSpinnerAdapter.add(additionalNamesArray[i]);
			}
		}
		for (int i = 0; i < defaultNameList.length; i++) {
			nameSpinnerAdapter.add(defaultNameList[i]);
		}

		nameSpinner = (Spinner) thisView.findViewById(R.id.name_spinner); 
		nameSpinner.setAdapter(nameSpinnerAdapter);
		thisView.findViewById(R.id.name_save_default_button).setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				String enteredText = getRoomNameFromEditText();

				if (enteredText == null || enteredText.trim().length() == 0) {
					return;
				}

				String temp = prefs.getString("USER_ROOM_NAMES", "");
				if (temp.length() == 0) {
					temp = enteredText;
				} else {
					temp = temp + "," + enteredText;
				}
				prefs.edit().putString("USER_ROOM_NAMES", temp).commit();

				nameSpinnerAdapter.clear();
				nameSpinnerAdapter.add("< CUSTOM >");
				String additionalNames = prefs.getString("USER_ROOM_NAMES", "");
				if (additionalNames.length() > 0) {
					String[] additionalNamesArray = additionalNames.split(",");
					for (int i = 0; i < additionalNamesArray.length; i++) {
						nameSpinnerAdapter.add(additionalNamesArray[i]);						
					}
				}
				String[] defaultNameList = getResources().getStringArray(R.array.name_array);
				for (int i = 0; i < defaultNameList.length; i++) {
					nameSpinnerAdapter.add(defaultNameList[i]);						
				}
				nameSpinnerAdapter.notifyDataSetChanged();
				String s;

				for (int i = 0; i < nameSpinner.getCount(); i++) {
					s = nameSpinner.getItemAtPosition(i).toString();
					if (s.equals(enteredText)) {
						nameSpinner.setSelection(i);
						((EditText) thisView.findViewById(R.id.name_editText)).setText("");
						thisView.findViewById(R.id.name_custom_wrapper).setVisibility(View.GONE);
						break;
					}
				}
			}
		});

		nameSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				if (position == 0) {
					thisView.findViewById(R.id.name_custom_wrapper).setVisibility(View.VISIBLE);
					thisView.findViewById(R.id.name_editText).requestFocus();
				} else {
					thisView.findViewById(R.id.name_custom_wrapper).setVisibility(View.GONE);
					((EditText) thisView.findViewById(R.id.name_editText)).setText(parent.getItemAtPosition(position).toString());
				}
			}
			public void onNothingSelected(AdapterView<?> parent) {}
		});

		if (thisRoom.getName() != null && thisRoom.getName().length() > 0) {
			boolean found = false;
			String thisName = thisRoom.getName();
			((EditText) thisView.findViewById(R.id.name_editText)).setText(thisName);

			for (int i = 0; i < nameSpinner.getAdapter().getCount(); i++) {
				if (thisName.equals(nameSpinner.getAdapter().getItem(i).toString())) {
					nameSpinner.setSelection(i);
					found = true;
					break;
				}
			}

			if (!found) {
				nameSpinner.setSelection(0);
			}
		}


		final RadioGroup winDoorSquareCustomRadioGroup = (RadioGroup) thisView.findViewById(R.id.winDoor_squareCustom_radioGroup);
		final RelativeLayout winDoorLenWidWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoorSquareWrapper);
		final RelativeLayout winDoorAreaWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoorAreaWrapper);
		winDoorAreaWrapper.setVisibility(View.GONE);
		winDoorSquareCustomRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (checkedId == R.id.winDoor_square_radioButton) {
					winDoorLenWidWrapper.setVisibility(View.VISIBLE);
					winDoorAreaWrapper.setVisibility(View.GONE);
				} else if (checkedId == R.id.winDoor_custom_radioButton) {
					winDoorLenWidWrapper.setVisibility(View.GONE);
					winDoorAreaWrapper.setVisibility(View.VISIBLE);
				}
			}
		});

		final RadioGroup celFloorSquareCustomRadioGroup = (RadioGroup) thisView.findViewById(R.id.celFloor_squareCustom_radioGroup);
		final RelativeLayout celFloorLenWidWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloorSquareWrapper);
		final RelativeLayout celFloorAreaWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloorAreaWrapper);
		celFloorAreaWrapper.setVisibility(View.GONE);
		celFloorSquareCustomRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (checkedId == R.id.celFloor_square_radioButton) {
					celFloorLenWidWrapper.setVisibility(View.VISIBLE);
					celFloorAreaWrapper.setVisibility(View.GONE);

					RelativeLayout lengthWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloor_width_wrapper);
					RelativeLayout heightWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloor_length_wrapper);
					RelativeLayout constNoWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloor_constNo_wrapper);
					lengthWrapper.setBackgroundResource(R.drawable.clear_error_background);
					heightWrapper.setBackgroundResource(R.drawable.clear_error_background);
					constNoWrapper.setBackgroundResource(R.drawable.clear_error_background);

				} else if (checkedId == R.id.celFloor_custom_radioButton) {
					celFloorLenWidWrapper.setVisibility(View.GONE);
					celFloorAreaWrapper.setVisibility(View.VISIBLE);

					RelativeLayout areaWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloorAreaWrapper);
					RelativeLayout constNoWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloor_constNo_wrapper);

					areaWrapper.setBackgroundResource(R.drawable.clear_error_background);
					constNoWrapper.setBackgroundResource(R.drawable.clear_error_background);
				}
			}
		});

		final Button wallConstNoWizard = (Button) thisView.findViewById(R.id.room_const_wizard_button);
		wallConstNoWizard.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				//				wallConstNoWizard.requestFocus();
				String[] s = new String[] {"Walls"};
				activity.displayConstNoDialog(thisView.getContext(), s);
			}
		});

		wallList = (ListView) thisView.findViewById(R.id.room_list);
		final RoomComponentListAdapter<Wall> wallAdapter = new RoomComponentListAdapter<Wall>(thisView.getContext(), thisRoom.getWalls());
		wallList.setAdapter(wallAdapter);

		final Button addWall = (Button) thisView.findViewById(R.id.room_add_button);
		addWall.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				//				addWall.requestFocus();
				boolean fail = false;

				EditText lengthMajorUnit = (EditText) thisView.findViewById(R.id.room_length_ft);
				EditText lengthMinorUnit = (EditText) thisView.findViewById(R.id.room_length_in);
				EditText widthMajorUnit = (EditText) thisView.findViewById(R.id.room_width_ft);
				EditText widthMinorUnit = (EditText) thisView.findViewById(R.id.room_width_in);
				EditText constNo = (EditText) thisView.findViewById(R.id.room_const_no);

				RelativeLayout lengthWrapper = (RelativeLayout) thisView.findViewById(R.id.wallLengthWrapper);
				RelativeLayout heightWrapper = (RelativeLayout) thisView.findViewById(R.id.wallHeightWrapper);
				RelativeLayout constNoWrapper = (RelativeLayout) thisView.findViewById(R.id.wallConstNoWrapper);
				lengthWrapper.setBackgroundResource(R.drawable.clear_error_background);
				heightWrapper.setBackgroundResource(R.drawable.clear_error_background);
				constNoWrapper.setBackgroundResource(R.drawable.clear_error_background);

				CompassSelector compassSelector = (CompassSelector) thisView.findViewById(R.id.room_facing_spinner);

				int[] dims = new int[4];
				String[] reader = new String[4];
				reader[0] = lengthMajorUnit.getText().toString();
				reader[1] = lengthMinorUnit.getText().toString();
				reader[2] = widthMajorUnit.getText().toString();
				reader[3] = widthMinorUnit.getText().toString();

				if ((reader[0] == null || reader[0].length() == 0 || Integer.valueOf(reader[0]) == 0)
						&& (reader[1] == null || reader[1].length() == 0 || Integer.valueOf(reader[1]) == 0)) {
					// error
					lengthWrapper.setBackgroundResource(R.drawable.error_background);
					fail = true;
				} else {
					if (reader[0] != null && reader[0].length() > 0) {
						dims[0] = Integer.parseInt(reader[0]);
					} else {
						dims[0] = 0;
					}

					if (reader[1] != null && reader[1].length() > 0) {
						dims[1] = Integer.parseInt(reader[1]);
					} else {
						dims[1] = 0;
					}
				}

				if ((reader[2] == null || reader[2].length() == 0 || Integer.valueOf(reader[2]) == 0)
						&& (reader[3] == null || reader[3].length() == 0 || Integer.valueOf(reader[3]) == 0)) {
					// error
					heightWrapper.setBackgroundResource(R.drawable.error_background);
					fail = true;
				} else {
					if (reader[2] != null && reader[2].length() > 0) {
						dims[2] = Integer.parseInt(reader[2]);
					} else {
						dims[2] = 0;
					}

					if (reader[3] != null && reader[3].length() > 0) {
						dims[3] = Integer.parseInt(reader[3]);
					} else {
						dims[3] = 0;
					}
				}

				String constNoString = constNo.getText().toString();
				if (constNoString == null || constNoString.length() == 0) {
					// error
					constNoWrapper.setBackgroundResource(R.drawable.error_background);
					fail = true;
				} else {
					TableParser parser = new TableParser(thisView.getContext(), R.raw.heatgain);
					if (!parser.checkItemExists(constNoString, "Walls")) {
						// error
						constNoWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					}
				}

				if (fail) {
					return;
				}

				Wall newWall = thisRoom.getNewWall();
				newWall.setDimensions(dims);
				newWall.setFacing(compassSelector.getSelectedItemPosition());
				newWall.setConstructionNumber(constNoString);

				thisRoom.addWall(newWall);
				wallAdapter.notifyDataSetChanged();

				lengthMajorUnit.setText("");
				lengthMinorUnit.setText("");
				widthMajorUnit.setText("");
				widthMinorUnit.setText("");
				compassSelector.setSelection(0);
				constNo.setText("");
				somethingChanged = true;
			}
		});

		final Button celFloorConstNoWizard = (Button) thisView.findViewById(R.id.celFloor_const_wizard_button);
		celFloorConstNoWizard.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				//				celFloorConstNoWizard.requestFocus();

				String[] s = new String[] {"Ceilings & Floors"};
				activity.displayConstNoDialog(thisView.getContext(), s);
			}
		});

		final EditText area = (EditText) thisView.findViewById(R.id.celFloor_area);
		area.addTextChangedListener(new TextWatcher() {
			public void onTextChanged(CharSequence s, int start, int before, int count) {}
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
			public void afterTextChanged(Editable s) {
				isCathedral[0] = false;
				isCathedral[1] = false;
			}
		});


		celFloorList = (ListView) thisView.findViewById(R.id.celFloor_list);
		final RoomComponentListAdapter<CeilingFloor> celFloorAdapter = new RoomComponentListAdapter<CeilingFloor>(thisView.getContext(), thisRoom.getCeilingsFloors());
		celFloorList.setAdapter(celFloorAdapter);

		final Button addCelFloor = (Button) thisView.findViewById(R.id.celFloor_add_button);
		addCelFloor.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				//				addCelFloor.requestFocus();

				boolean fail = false;
				int[] dims = new int[4];
				String[] reader = new String[4];

				EditText lengthMajorUnit = (EditText) thisView.findViewById(R.id.celFloor_length_ft);
				EditText lengthMinorUnit = (EditText) thisView.findViewById(R.id.celFloor_length_in);
				EditText widthMajorUnit = (EditText) thisView.findViewById(R.id.celFloor_width_ft);
				EditText widthMinorUnit = (EditText) thisView.findViewById(R.id.celFloor_width_in);
				EditText constNo = (EditText) thisView.findViewById(R.id.celFloor_const_no);

				RelativeLayout lengthWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloor_length_wrapper);
				RelativeLayout widthWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloor_width_wrapper);
				RelativeLayout areaWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloorAreaWrapper);
				RelativeLayout constNoWrapper = (RelativeLayout) thisView.findViewById(R.id.celFloor_constNo_wrapper);

				RadioGroup celFloorRadGroup = (RadioGroup) thisView.findViewById(R.id.celFloor_squareCustom_radioGroup);

				if (celFloorRadGroup.getCheckedRadioButtonId() == R.id.celFloor_square_radioButton) {

					lengthWrapper.setBackgroundResource(R.drawable.clear_error_background);
					widthWrapper.setBackgroundResource(R.drawable.clear_error_background);

					reader[0] = lengthMajorUnit.getText().toString();
					reader[1] = lengthMinorUnit.getText().toString();
					reader[2] = widthMajorUnit.getText().toString();
					reader[3] = widthMinorUnit.getText().toString();

					if ((reader[0] == null || reader[0].length() == 0 || Integer.valueOf(reader[0]) == 0)
							&& (reader[1] == null || reader[1].length() == 0 || Integer.valueOf(reader[1]) == 0)) {
						// error
						lengthWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						if (reader[0] != null && reader[0].length() > 0) {
							dims[0] = Integer.parseInt(reader[0]);
						} else {
							dims[0] = 0;
						}

						if (reader[1] != null && reader[1].length() > 0) {
							dims[1] = Integer.parseInt(reader[1]);
						} else {
							dims[1] = 0;
						}
					}

					if ((reader[2] == null || reader[2].length() == 0 || Integer.valueOf(reader[2]) == 0)
							&& (reader[3] == null || reader[3].length() == 0 || Integer.valueOf(reader[3]) == 0)) {
						// error
						widthWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						if (reader[2] != null && reader[2].length() > 0) {
							dims[2] = Integer.parseInt(reader[2]);
						} else {
							dims[2] = 0;
						}

						if (reader[3] != null && reader[3].length() > 0) {
							dims[3] = Integer.parseInt(reader[3]);
						} else {
							dims[3] = 0;
						}
					}

				} else if (celFloorRadGroup.getCheckedRadioButtonId() == R.id.celFloor_custom_radioButton) {

					areaWrapper.setBackgroundResource(R.drawable.clear_error_background);
					reader[0] = area.getText().toString();

					if (reader[0] == null || reader[0].length() == 0 || Integer.valueOf(reader[0]) == 0) {
						// error
						areaWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						dims[0] = Integer.parseInt(reader[0]);
					}
				}

				constNoWrapper.setBackgroundResource(R.drawable.clear_error_background);
				String constNoString = constNo.getText().toString();
				if (constNoString == null || constNoString.length() == 0) {
					// error
					constNoWrapper.setBackgroundResource(R.drawable.error_background);
					fail = true;
				} else {
					TableParser parser = new TableParser(thisView.getContext(), R.raw.heatgain);
					if (!parser.checkItemExists(constNoString, "Ceilings & Floors")) {
						// error
						constNoWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					}
				}

				if (fail) {
					return;
				}

				CeilingFloor newCelFloor = thisRoom.getNewCeilingFloor();

				if (celFloorRadGroup.getCheckedRadioButtonId() == R.id.celFloor_square_radioButton) {
					newCelFloor.setDimensions(dims);
				} else if (celFloorRadGroup.getCheckedRadioButtonId() == R.id.celFloor_custom_radioButton) {
					newCelFloor.setArea(dims[0], isCathedral);
				}

				newCelFloor.setConstructionNumber(constNoString);

				thisRoom.addCeilingFloor(newCelFloor);
				celFloorAdapter.notifyDataSetChanged();

				lengthMajorUnit.setText("");
				lengthMinorUnit.setText("");
				widthMajorUnit.setText("");
				widthMinorUnit.setText("");
				area.setText("");
				constNo.setText("");
				isCathedral[0] = false;
				isCathedral[1] = false;
				somethingChanged = true;
			}
		});

		final Button celFloorAreaWizardButton = (Button) thisView.findViewById(R.id.celFloor_area_wizard_button);
		celFloorAreaWizardButton.setOnClickListener(new OnClickListener() {			
			public void onClick(View v) {

				//				celFloorAreaWizardButton.requestFocus();

				RelativeLayout widthWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_width_wrapper);
				RelativeLayout heightWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_height_wrapper);
				RelativeLayout areaWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoorAreaWrapper);

				widthWrapper.setBackgroundResource(R.drawable.clear_error_background);
				heightWrapper.setBackgroundResource(R.drawable.clear_error_background);
				areaWrapper.setBackgroundResource(R.drawable.clear_error_background);

				activity.displayAreaWizardDialog(thisView.getContext(), CEILING_WIZARD_SELECTION);
			}
		});

		final Button winDoorAreaWizardButton = (Button) thisView.findViewById(R.id.winDoor_area_wizard_button);
		winDoorAreaWizardButton.setOnClickListener(new OnClickListener() {			
			public void onClick(View v) {

				//				winDoorAreaWizardButton.requestFocus();

				RelativeLayout widthWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_width_wrapper);
				RelativeLayout heightWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_height_wrapper);
				RelativeLayout areaWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoorAreaWrapper);

				widthWrapper.setBackgroundResource(R.drawable.clear_error_background);
				heightWrapper.setBackgroundResource(R.drawable.clear_error_background);
				areaWrapper.setBackgroundResource(R.drawable.clear_error_background);

				activity.displayAreaWizardDialog(thisView.getContext(), WINDOW_WIZARD_SELECTION, 0, null);
			}
		});

		final Button winDoorConstNoWizard = (Button) thisView.findViewById(R.id.winDoor_const_wizard_button);
		winDoorConstNoWizard.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				//				winDoorConstNoWizard.requestFocus();

				String[] s = new String[] {"Windows & Doors"};
				activity.displayConstNoDialog(thisView.getContext(), s);
			}
		});

		final Button winDoorShadeWizard = (Button) thisView.findViewById(R.id.winDoor_shade_wizard_button);
		winDoorShadeWizard.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				//				winDoorShadeWizard.requestFocus();

				boolean fail = false;
				int[] dims = new int[2];
				String[] reader = new String[2];

				EditText width = (EditText) thisView.findViewById(R.id.winDoor_width_in);
				EditText height= (EditText) thisView.findViewById(R.id.winDoor_height_in);
				EditText area = (EditText) thisView.findViewById(R.id.winDoor_area);

				RelativeLayout widthWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_width_wrapper);
				RelativeLayout heightWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_height_wrapper);
				RelativeLayout areaWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoorAreaWrapper);

				RadioGroup winDoorRadGroup = (RadioGroup) thisView.findViewById(R.id.winDoor_squareCustom_radioGroup);

				widthWrapper.setBackgroundResource(R.drawable.clear_error_background);
				heightWrapper.setBackgroundResource(R.drawable.clear_error_background);
				areaWrapper.setBackgroundResource(R.drawable.clear_error_background);

				if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_square_radioButton) {

					reader[0] = width.getText().toString();
					reader[1] = height.getText().toString();

					if (reader[0] == null || reader[0].length() == 0 || Integer.valueOf(reader[0]) == 0) {
						// error
						widthWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						if (reader[0] != null && reader[0].length() > 0) {
							dims[0] = Integer.parseInt(reader[0]);
						} else {
							dims[0] = 0;
						}
					}

					if (reader[1] == null || reader[1].length() == 0 || Integer.valueOf(reader[1]) == 0) {
						// error
						heightWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						if (reader[1] != null && reader[1].length() > 0) {
							dims[1] = Integer.parseInt(reader[1]);
						} else {
							dims[1] = 0;
						}
					}

					if (fail) {
						Toast.makeText(thisView.getContext(), "Can't calculate shaded area without both height and width!", Toast.LENGTH_LONG).show();
						return;
					}

					activity.displayAreaWizardDialog(thisView.getContext(), SHADE_WIZARD_SELECTION, WINDOW_SQUARE, dims);

				} else if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_custom_radioButton) {

					reader[0] = area.getText().toString();

					if (reader[0] == null || reader[0].length() == 0 || Integer.valueOf(reader[0]) == 0) {
						// error
						areaWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						dims[0] = Integer.parseInt(reader[0]);
					}

					if (fail) {
						Toast.makeText(thisView.getContext(), "Can't calculate shaded area without first knowing total area!", Toast.LENGTH_LONG).show();
						return;
					}

					activity.displayAreaWizardDialog(thisView.getContext(), SHADE_WIZARD_SELECTION, WINDOW_AREA, dims);
				}
			}
		});

		winDoorList = (ListView) thisView.findViewById(R.id.winDoor_list);
		final RoomComponentListAdapter<WindowDoor> winDoorAdapter = new RoomComponentListAdapter<WindowDoor>(thisView.getContext(), thisRoom.getWindowsDoors());
		winDoorList.setAdapter(winDoorAdapter);

		final Button winDoorAddButton = (Button) thisView.findViewById(R.id.winDoor_add_button);
		winDoorAddButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				boolean fail = false;
				int[] dims = new int[4];
				String[] reader = new String[4];
				int shadeAreaInt = 0;

				EditText width = (EditText) thisView.findViewById(R.id.winDoor_width_in);
				EditText height= (EditText) thisView.findViewById(R.id.winDoor_height_in);
				EditText area = (EditText) thisView.findViewById(R.id.winDoor_area);
				EditText shadeArea = (EditText) thisView.findViewById(R.id.winDoor_shade);
				EditText constNo = (EditText) thisView.findViewById(R.id.winDoor_const_no);
				EditText qty = (EditText) thisView.findViewById(R.id.winDoor_qty);

				RelativeLayout widthWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_width_wrapper);
				RelativeLayout heightWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_height_wrapper);
				RelativeLayout areaWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoorAreaWrapper);
				RelativeLayout constNoWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_constNo_wrapper);
				RelativeLayout qtyWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_qty_wrapper);
				RelativeLayout shadedAreaWrapper = (RelativeLayout) thisView.findViewById(R.id.winDoor_shadedAreaWrapper);

				CompassSelector compassSelector = (CompassSelector) thisView.findViewById(R.id.winDoor_facing_spinner);
				RadioGroup winDoorRadGroup = (RadioGroup) thisView.findViewById(R.id.winDoor_squareCustom_radioGroup);

				widthWrapper.setBackgroundResource(R.drawable.clear_error_background);
				heightWrapper.setBackgroundResource(R.drawable.clear_error_background);
				areaWrapper.setBackgroundResource(R.drawable.clear_error_background);
				constNoWrapper.setBackgroundResource(R.drawable.clear_error_background);
				qtyWrapper.setBackgroundResource(R.drawable.clear_error_background);
				shadedAreaWrapper.setBackgroundResource(R.drawable.clear_error_background);

				if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_square_radioButton) {

					reader[0] = width.getText().toString();
					reader[1] = height.getText().toString();

					if (reader[0] == null || reader[0].length() == 0 || Integer.valueOf(reader[0]) == 0) {
						// error
						widthWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						if (reader[0] != null && reader[0].length() > 0) {
							dims[0] = Integer.parseInt(reader[0]);
						} else {
							dims[0] = 0;
						}
					}

					if (reader[1] == null || reader[1].length() == 0 || Integer.valueOf(reader[1]) == 0) {
						// error
						heightWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						if (reader[1] != null && reader[1].length() > 0) {
							dims[1] = Integer.parseInt(reader[1]);
						} else {
							dims[1] = 0;
						}
					}

				} else if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_custom_radioButton) {

					reader[0] = area.getText().toString();

					if (reader[0] == null || reader[0].length() == 0 || Integer.valueOf(reader[0]) == 0) {
						// error
						areaWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					} else {
						dims[0] = Integer.parseInt(reader[0]);
					}

				}

				String constNoString = constNo.getText().toString();
				if (constNoString == null || constNoString.length() == 0) {
					// error
					constNoWrapper.setBackgroundResource(R.drawable.error_background);
					fail = true;
				} else {
					TableParser parser = new TableParser(thisView.getContext(), R.raw.heatgain);
					if (!parser.checkItemExists(constNoString, "Windows & Doors")) {
						// error
						constNoWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					}
				}

				String shadeString = shadeArea.getText().toString();
				if (shadeString == null || shadeString.length() == 0) {
					// default to 0
					shadeAreaInt = 0;
				} else {
					shadeAreaInt = Integer.parseInt(shadeString);
				}

				if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_square_radioButton) {
					if (shadeAreaInt > (dims[0] * dims[1])) {
						shadedAreaWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					}
				} else if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_custom_radioButton) {
					if (shadeAreaInt > dims[0]) {
						shadedAreaWrapper.setBackgroundResource(R.drawable.error_background);
						fail = true;
					}
				}


				String qtyString = qty.getText().toString();
				int qtyInt = 0;
				if (qtyString == null || qtyString.length() == 0 || Integer.valueOf(qtyString) == 0) {
					// error
					qtyWrapper.setBackgroundResource(R.drawable.error_background);
					fail = true;
				} else {
					if (qtyString != null && Integer.valueOf(qtyString) > 1) {
						qtyInt = Integer.parseInt(qtyString);
					} else {
						qtyInt = 1;
					}
				}

				if (fail) {
					return;
				}

				if (windowType == 0) {
					if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_square_radioButton) {
						windowType = WINDOW_SQUARE;
					} else if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_custom_radioButton) {
						windowType = WINDOW_AREA;
					}
				}

				WindowDoor newWinDoor = thisRoom.getNewWindowDoor(windowType);

				if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_square_radioButton) {
					newWinDoor.setDimensions(dims);
				} else if (winDoorRadGroup.getCheckedRadioButtonId() == R.id.winDoor_custom_radioButton) {
					newWinDoor.setArea(dims[0]);
				}

				newWinDoor.setShadedArea(shadeAreaInt);
				newWinDoor.setQty(qtyInt);
				newWinDoor.setFacing(compassSelector.getSelectedItemPosition());
				newWinDoor.setConstructionNumber(constNoString);

				thisRoom.addWindowDoor(newWinDoor);
				winDoorAdapter.notifyDataSetChanged();

				width.setText("");
				height.setText("");
				area.setText("");
				shadeArea.setText("");
				constNo.setText("");
				qty.setText("1");
				windowType = 0;
				somethingChanged = true;
			}
		});

		sensibleList = (ListView) thisView.findViewById(R.id.load_list);
		final RoomComponentListAdapter<SensibleLoad> sensibleAdapter = new RoomComponentListAdapter<SensibleLoad>(thisView.getContext(), thisRoom.getSensibleLoads());
		sensibleList.setAdapter(sensibleAdapter);

		final Button lightingButton = (Button) thisView.findViewById(R.id.load_lighting_button);
		lightingButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				activity.displaySensibleLoadDialog(thisView.getContext(), SensibleLoad.LIGHTING);
			}
		});

		final Button occupantButton = (Button) thisView.findViewById(R.id.load_occupant_button);
		occupantButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				activity.displaySensibleLoadDialog(thisView.getContext(), SensibleLoad.OCCUPANT);
			}
		});

		final Button appliancesButton = (Button) thisView.findViewById(R.id.load_appliances_button);
		appliancesButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				activity.displaySensibleLoadDialog(thisView.getContext(), SensibleLoadDialog.APPLIANCE_WIZARD_SELECTION);
			}
		});

		final Button commercialButton = (Button) thisView.findViewById(R.id.load_commercial_button);
		commercialButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				activity.displaySensibleLoadDialog(thisView.getContext(), SensibleLoadDialog.COMMERCIAL_WIZARD_SELECTION);
			}
		});

		wallList.setOnItemLongClickListener(new OnItemLongClickListener() {
			public boolean onItemLongClick(AdapterView<?> parent, View view, int id, long position) {
				activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.DELETE, WALL, position);
				return false;
			}
		});

		winDoorList.setOnItemLongClickListener(new OnItemLongClickListener() {
			public boolean onItemLongClick(AdapterView<?> parent, View view, int id, long position) {
				activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.DELETE, WINDOW_DOOR, position);
				return false;
			}
		});

		celFloorList.setOnItemLongClickListener(new OnItemLongClickListener() {
			public boolean onItemLongClick(AdapterView<?> parent, View view, int id, long position) {
				activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.DELETE, CEILING_FLOOR, position);
				return false;
			}
		});

		sensibleList.setOnItemLongClickListener(new OnItemLongClickListener() {
			public boolean onItemLongClick(AdapterView<?> parent, View view, int id, long position) {
				activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.DELETE, SENSIBLE_LOAD, position);
				return false;
			}
		});

		ImageView cancelButton = (ImageView) thisView.findViewById(R.id.cancel_button);
		cancelButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				
				if (somethingChanged) {
					activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.DISCARD_CHANGES, 0, 0);
				} else {
					activity.closeRoomEditor(null);
				}
			}
		});
		
		ImageView saveButton = (ImageView) thisView.findViewById(R.id.save_button);
		saveButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				if (nameSpinner.getSelectedItemPosition() != 0) {
					thisRoom.setName(nameSpinner.getSelectedItem().toString());
				} else {
					if (getRoomNameFromEditText().length() == 0 || getRoomNameFromEditText() == "") {
						activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.NO_ROOM_NAME, 0, 0);
						return;
					} else {
						thisRoom.setName(getRoomNameFromEditText());
					}
				}

				if (thisRoom.getTotalRoomLoad(thisView.getContext()) <= 0) {
					activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.NO_ROOM_LOAD, 0, 0);
					return;
				} else {
					activity.closeRoomEditor(thisRoom);
				}
			}
		});
		
		ImageView wallHelp = (ImageView) thisView.findViewById(R.id.wall_help);
		wallHelp.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				activity.displayInfoDialog(thisView.getContext(), InformationDialog.WALL_HELP, null);
			}
		});

		ImageView celfloorHelp = (ImageView) thisView.findViewById(R.id.ceiling_help);
		celfloorHelp.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				activity.displayInfoDialog(thisView.getContext(), InformationDialog.CELFLOOR_HELP, null);
			}
		});

		ImageView sensibleHelp = (ImageView) thisView.findViewById(R.id.sensible_help);
		sensibleHelp.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				activity.displayInfoDialog(thisView.getContext(), InformationDialog.SENSIBLE_HELP, null);
			}
		});

		return thisView;
	}

	public void setEditText(int which, String s) {
		if (which == WALL_CONST_NO) {
			EditText wallConstNo = (EditText) thisView.findViewById(R.id.room_const_no);
			wallConstNo.setText(s);
			wallConstNo.requestFocus();
		} else if (which == CEILING_FLOOR_CONST_NO) {
			EditText celFloorConstNo = (EditText) thisView.findViewById(R.id.celFloor_const_no);
			celFloorConstNo.setText(s);
			celFloorConstNo.requestFocus();
		} else if (which == WINDOW_DOOR_CONST_NO) {
			EditText winDoorConstNo = (EditText) thisView.findViewById(R.id.winDoor_const_no);
			winDoorConstNo.setText(s);
			winDoorConstNo.requestFocus();
		}
	}

	public void setEditText(int which, double d) {
		if (which == CATHEDRAL_CEILING || which == VAULTED_CEILING) {
			EditText celFloorArea = (EditText) thisView.findViewById(R.id.celFloor_area);
			celFloorArea.setText(String.valueOf((int) d));
			celFloorArea.requestFocus();

			if (which == CATHEDRAL_CEILING) {
				isCathedral[0] = true;
				isCathedral[1] = false;
			} else if (which == VAULTED_CEILING) {
				isCathedral[0] = false;
				isCathedral[1] = true;
			}
		} else if (which == WINDOW_ARCHED || which == WINDOW_ELLIPSE || which == WINDOW_HALF_ARCH
				|| which == WINDOW_HALF_ELLIPSE || which == WINDOW_TRIANGULAR) {
			EditText winDoorArea = (EditText) thisView.findViewById(R.id.winDoor_area);
			windowType = which;
			winDoorArea.setText(String.valueOf((int) d));
			winDoorArea.requestFocus();
		}
	}

	public void setEditText(int which, double[] d, int facing) {
		if (which == WINDOW_ARCHED || which == WINDOW_ELLIPSE || which == WINDOW_HALF_ARCH
				|| which == WINDOW_HALF_ELLIPSE || which == WINDOW_TRIANGULAR) {

			EditText winDoorArea = (EditText) thisView.findViewById(R.id.winDoor_area);
			EditText winDoorShade = (EditText) thisView.findViewById(R.id.winDoor_shade);
			CompassSelector winDoorFacingSpinner = (CompassSelector) thisView.findViewById(R.id.winDoor_facing_spinner);
			windowType = which;
			winDoorArea.setText(String.valueOf((int) d[0]));
			winDoorShade.setText(String.valueOf((int) d[1]));
			winDoorFacingSpinner.setSelection(facing);
			winDoorShade.requestFocus();

		} else if (which == WINDOW_SQUARE || which == WINDOW_AREA) {
			CompassSelector winDoorFacingSpinner = (CompassSelector) thisView.findViewById(R.id.winDoor_facing_spinner);			
			EditText winDoorShade = (EditText) thisView.findViewById(R.id.winDoor_shade);
			winDoorShade.setText(String.valueOf((int) d[1]));
			winDoorFacingSpinner.setSelection(facing);
			winDoorShade.requestFocus();

		} else if (which == SensibleLoad.LIGHTING) {
			somethingChanged = true;

			SensibleLoad newLight = thisRoom.getNewSensibleLoad(facing);
			newLight.setWatts((int) d[0], (int) d[1]);
			newLight.setQuantity((int) d[2]);
			thisRoom.addSensibleLoad(newLight);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();
		}
	}

	public void setEditText(int which, double[] d) {
		if (which == WINDOW_SQUARE || which == WINDOW_AREA) {
			EditText winDoorShade = (EditText) thisView.findViewById(R.id.winDoor_shade);
			winDoorShade.setText(String.valueOf((int) d[1]));
			winDoorShade.requestFocus();
		}
	}

	public void shadeAreaError() {
		((RelativeLayout) thisView.findViewById(R.id.winDoorAreaWrapper)).setBackgroundResource(R.drawable.error_background);

		Toast.makeText(thisView.getContext(), "To use the Overhang Shade Wizard, either enter square dimensions or use the Window Area Wizard", Toast.LENGTH_LONG).show();
	}

	public void setEditText(int which, double[] d, String[] returnList) {
		
		somethingChanged = true;

		if (which == SensibleLoad.OCCUPANT) {
			SensibleLoad newOccupant = thisRoom.getNewSensibleLoad(which);
			newOccupant.setWatts((int) d[1], 100);
			newOccupant.setQuantity((int) d[0]);
			newOccupant.setConstNo(returnList[0]);
			newOccupant.setName(returnList[1]);
			thisRoom.addSensibleLoad(newOccupant);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();

		} else if (which == SensibleLoad.APPLIANCE || which == SensibleLoad.COMMERCIAL) {
			SensibleLoad newAppliance = thisRoom.getNewSensibleLoad(which);
			newAppliance.setWatts((int) d[1], (int) d[2]);
			newAppliance.setQuantity((int) d[0]);
			newAppliance.setConstNo(returnList[0]);
			newAppliance.setName(returnList[1]);
			thisRoom.addSensibleLoad(newAppliance);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();

		} else if (which == SensibleLoad.APPLIANCE_KITCHEN_BTU) {
			SensibleLoad newAppliance = thisRoom.getNewSensibleLoad(which);
			newAppliance.setBTU((int) (d[1]));
			newAppliance.setQuantity((int) d[0]);
			newAppliance.setConstNo(returnList[0]);
			newAppliance.setName(returnList[1]);
			thisRoom.addSensibleLoad(newAppliance);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();

		} else if (which == SensibleLoad.APPLIANCE_KITCHEN_WATT) {
			SensibleLoad newAppliance = thisRoom.getNewSensibleLoad(which);
			newAppliance.setWatts((int) d[1], (int) d[2]);
			newAppliance.setQuantity((int) d[0]);
			newAppliance.setConstNo(returnList[0]);
			newAppliance.setName(returnList[1]);
			thisRoom.addSensibleLoad(newAppliance);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();

		} else if (which == SensibleLoad.APPLIANCE_FIREPLACE) {
			SensibleLoad newAppliance = thisRoom.getNewSensibleLoad(which);
			newAppliance.setBTU(0);
			newAppliance.setQuantity((int) d[0]);
			newAppliance.setConstNo(returnList[0]);
			newAppliance.setName(returnList[1]);
			thisRoom.addSensibleLoad(newAppliance);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();

		} else if (which == SensibleLoad.COMMERCIAL_CUSTOM_BTU) {
			SensibleLoad newCommercial = thisRoom.getNewSensibleLoad(which);
			newCommercial.setBTU((int) (d[1]));
			newCommercial.setQuantity((int) d[0]);
			newCommercial.setConstNo(returnList[0]);
			newCommercial.setName(returnList[1]);
			thisRoom.addSensibleLoad(newCommercial);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();

		} else if (which == SensibleLoad.COMMERCIAL_CUSTOM_WATT) {
			SensibleLoad newCommercial = thisRoom.getNewSensibleLoad(which);
			newCommercial.setWatts((int) d[1], (int) d[2]);
			newCommercial.setQuantity((int) d[0]);
			newCommercial.setConstNo(returnList[0]);
			newCommercial.setName(returnList[1]);
			thisRoom.addSensibleLoad(newCommercial);
			((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
			sensibleList.requestFocus();
		}
	}

	public void returnFromConfirmDialog(int dialogType, int type, long id) {

		if (dialogType == ConfirmDialog.DELETE) {
			if (type == WALL) {
				thisRoom.removeWall(id);
				((RoomComponentListAdapter<Wall>) wallList.getAdapter()).notifyDataSetChanged();
				somethingChanged = true;
			} else if (type == WINDOW_DOOR) {
				thisRoom.removeWinDoor(id);
				((RoomComponentListAdapter<WindowDoor>) winDoorList.getAdapter()).notifyDataSetChanged();
				somethingChanged = true;
			} else if (type == CEILING_FLOOR) {
				thisRoom.removeCelFloor(id);
				((RoomComponentListAdapter<CeilingFloor>) celFloorList.getAdapter()).notifyDataSetChanged();
				somethingChanged = true;
			} else if (type == SENSIBLE_LOAD) {
				thisRoom.removeSensibleLoad(id);
				((RoomComponentListAdapter<SensibleLoad>) sensibleList.getAdapter()).notifyDataSetChanged();
				somethingChanged = true;
			}
		} else if (dialogType == ConfirmDialog.DISCARD_CHANGES) {
			activity.closeRoomEditor(null);
		} else if (dialogType == ConfirmDialog.NO_ROOM_NAME) {
			
			thisRoom.setName("Room " + String.valueOf(thisRoom.getId()));
			
			if (thisRoom.getTotalRoomLoad(thisView.getContext()) <= 0) {
				activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.NO_ROOM_LOAD, 0, 0);
				return;
			} else {
				activity.closeRoomEditor(thisRoom);
			}
		} else if (dialogType == ConfirmDialog.NO_ROOM_LOAD) {
			activity.closeRoomEditor(thisRoom);
		}
	}

	protected String getRoomNameFromEditText() {
		return ((EditText) thisView.findViewById(R.id.name_editText)).getText().toString();
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);

		outState.putParcelable("NEW_ROOM_FRAGMENT_ROOM", thisRoom);
	}

	public long getRoomId() {
		return thisRoom.getId();
	}

	public Room forceSave() {

		if (nameSpinner.getSelectedItemPosition() != 0) {
			thisRoom.setName(nameSpinner.getSelectedItem().toString());
		} else {
			if (getRoomNameFromEditText().length() == 0 || getRoomNameFromEditText() == "") {
				thisRoom.setName("");
			} else {
				thisRoom.setName(getRoomNameFromEditText());
			}
		}

		return thisRoom;
	}
	
	public void cancelScreen() {
		if (somethingChanged) {
			activity.displayConfirmDialog(thisView.getContext(), ConfirmDialog.DISCARD_CHANGES, 0, 0);
		} else {
			activity.closeRoomEditor(null);
		}
	}
}
